package cn.xugongwei.microservicecommon.circuit;

import cn.xugongwei.microservicecommon.entity.UserEntity;
import cn.xugongwei.microservicecommon.service.UserClientService;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xugongwei (isxugongwei(a)gmail.com)
 * @version 1.0
 * @date 2019/4/10 12:15
 */
@Component
public class UserClientServiceFallbackFactory implements FallbackFactory<UserClientService> {

    @Override
    public UserClientService create(Throwable throwable) {
        return new UserClientService() {

            @Override
            public List<UserEntity> listUser() {
                List<UserEntity> list = new ArrayList<>();
                list.add(new UserEntity(0, "unknown", "unknown"));
                return list;
            }

            @Override
            public UserEntity getUserById(Integer id) {
                return new UserEntity(0, "unknown", "unknown");
            }
        };
    }
}
